#pragma once

#define compiletime_assert_rwonce_type(t)

#define WRITE_ONCE(x, val) \
    do{ *(volatile __typeof(x) *)&(x) = (val); }while (0)

/*
 * Use __READ_ONCE() instead of READ_ONCE() if you do not require any
 * atomicity. Note that this may result in tears!
 */
#ifndef __READ_ONCE
#define __READ_ONCE(x) (*(const volatile __typeof(x) *)&(x))
#endif

#define READ_ONCE(x)                       \
    ({                                     \
        compiletime_assert_rwonce_type(x); \
        __READ_ONCE(x);                    \
    })
